#include <iostream>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
using namespace std;

int main()
{
	int fd = open("bite.txt", O_RDWR | O_CREAT | O_APPEND, 0666);
	if (fd == -1)
	{
		perror("open fail\n");
		return 1;
	}

	const char* str = "i like linux!\n";
	write(fd, str, strlen(str));

	lseek(fd, 0, SEEK_SET);

	char buffer[1024];
	ssize_t n = read(fd, buffer, sizeof(buffer) - 1);
	buffer[n] = '\0';
	printf("%s", buffer);

	close(fd);

	return 0;
}


